package o;

import android.content.Context;
import android.content.Intent;
import android.media.browse.MediaBrowser.MediaItem;
import android.media.session.MediaSession.Token;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.service.media.MediaBrowserService;
import android.service.media.MediaBrowserService.BrowserRoot;
import android.service.media.MediaBrowserService.Result;
import android.support.v4.media.session.MediaSessionCompat;
import androidx.annotation.RequiresApi;
import java.util.ArrayList;
import java.util.List;

@RequiresApi(21)
public class lr {

    public interface d {
        c ˋ(String str, int i, Bundle bundle);

        void ˎ(String str, e<List<Parcel>> eVar);
    }

    static class b extends MediaBrowserService {
        final d ˏ;

        b(Context context, d dVar) {
            attachBaseContext(context);
            this.ˏ = dVar;
        }

        public BrowserRoot onGetRoot(String str, int i, Bundle bundle) {
            MediaSessionCompat.ˏ(bundle);
            c ˋ = this.ˏ.ˋ(str, i, bundle == null ? null : new Bundle(bundle));
            if (ˋ == null) {
                return null;
            }
            return new BrowserRoot(ˋ.ˋ, ˋ.ˏ);
        }

        public void onLoadChildren(String str, Result<List<MediaItem>> result) {
            this.ˏ.ˎ(str, new e(result));
        }
    }

    public static class c {
        final String ˋ;
        final Bundle ˏ;

        public c(String str, Bundle bundle) {
            this.ˋ = str;
            this.ˏ = bundle;
        }
    }

    public static class e<T> {
        Result ˎ;

        e(Result result) {
            this.ˎ = result;
        }

        public void ˋ(T t) {
            if (t instanceof List) {
                this.ˎ.sendResult(ˊ((List) t));
            } else if (t instanceof Parcel) {
                Parcel parcel = (Parcel) t;
                parcel.setDataPosition(0);
                this.ˎ.sendResult(MediaItem.CREATOR.createFromParcel(parcel));
                parcel.recycle();
            } else {
                this.ˎ.sendResult(null);
            }
        }

        List<MediaItem> ˊ(List<Parcel> list) {
            if (list == null) {
                return null;
            }
            List<MediaItem> arrayList = new ArrayList();
            for (Parcel parcel : list) {
                parcel.setDataPosition(0);
                arrayList.add(MediaItem.CREATOR.createFromParcel(parcel));
                parcel.recycle();
            }
            return arrayList;
        }
    }

    public static Object ˋ(Context context, d dVar) {
        return new b(context, dVar);
    }

    public static void ˎ(Object obj) {
        ((MediaBrowserService) obj).onCreate();
    }

    public static IBinder ˎ(Object obj, Intent intent) {
        return ((MediaBrowserService) obj).onBind(intent);
    }

    public static void ˊ(Object obj, Object obj2) {
        ((MediaBrowserService) obj).setSessionToken((Token) obj2);
    }

    public static void ˏ(Object obj, String str) {
        ((MediaBrowserService) obj).notifyChildrenChanged(str);
    }
}
